<%--
  Created by IntelliJ IDEA.
  User: 92329
  Date: 2018/4/23
  Time: 21:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="common.jspf"%>
<html>
<head>
    <link href="${hkxyPath}/resources/css/bootstrap-datetimepicker.css" rel='stylesheet' type='text/css'/>
    <script src="${hkxyPath}/resources/js/bootstrap-datetimepicker.js" type="text/javascript"></script>
    <script src="${hkxyPath}/resources/js/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
    <title>个人中心</title>
    <script>
        var adminid='${sessionScope.admin.id}';
        $(function () {
            var sex='${sessionScope.admin.sex}';
            $("#savediv").hide();
            $("#modifyinfo").show();

            if (sex == '男') {
                $("#sex").find("option[value='男']").attr("selected",true);
            } else if (admin.sex == '女') {
                $("#sex").find("option[value='女']").attr("selected",true);
            } else {
                $("#sex").find("option[value='0']").attr("selected",true);
            }
            var birth='${sessionScope.admin.birthday}';
            var birthday=dateFormat(birth);
            $("#birth").val(birthday);
        });

        function modifypersonalinfo() {
            $("fieldset").removeAttr("disabled");
            $("#savediv").show();
            $("#modifyinfo").hide();
        }
        function saveypersonalinfo() {
         /* var param=$("#personalform").serializeArray();
            param.push({"id":adminid});*/
            var birth=$("#birth").val();
          //  var birthday=new Date($("#birth").val().replace("-", "/").replace("-", "/"))
            var param=$("#personalform").serialize()+"&"+"id="+adminid+"&"+"birth="+birth;
            console.log(param);
            $.post("${hkxyPath}/user/personal-update",param,function (result) {
                if(result.code==1){
                    tips(1);
                    $("fieldset").attr("disabled","disabled");
                    $("#savediv").hide();
                    $("#modifyinfo").show();
                }else {
                    tips(0)
                }
            });
        }
        function cancelmodify(){
            $("fieldset").attr("disabled","disabled");
            $("#savediv").hide();
            $("#modifyinfo").show();
        }
        //日期插件
        $('.form_date').datetimepicker({
            language:  'zh-CN',	//中文
            format:'yyyy-mm-dd',
            weekStart: 0,	//周日开始
            todayBtn:  0,	//不显示今日按钮
            autoclose: 1,	//开启自动关闭
            todayHighlight: true,	//今日高亮
            startView: 2,
            minView: "month",	//只显示到月份
            forceParse: 0
        });

    </script>
</head>
<body>
<%@include file="tips.jspf"%>
    <div>
        <div class="header-bottom-my1">
            <h2>个人资料</h2>
        </div>
        <form class="form-horizontal" role="form" id="personalform">
            <div class="form-group">
                <label for="username" class="col-sm-2 control-label">用户名：</label>
                <div class="col-sm-10">
                    <p id="username" style="padding-top: 8px">${sessionScope.admin.username}</p>
                </div>
            </div>
            <fieldset disabled>
            <div class="form-group">
                <label for="realname" class="col-sm-2 control-label">真实姓名：</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" name="realname" id="realname"placeholder="输入真实姓名" value="${sessionScope.admin.realname}">
                </div>
                <%--
                <div class="col-sm-7">
                    <span class="help-block">* 真实姓名修改后下次登录生效</span>
                </div>
                --%>
            </div>
            <div class="form-group">
                <label for="sex" class="col-sm-2 control-label">性别：</label>
                <div class="col-sm-3">
                    <select name="sex" id="sex" class="form-control">
                        <option value="0">选择性别</option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="birth" class="col-sm-2 control-label">生日：</label>
                <div class="col-sm-3">
                    <input class="form-control form_date" type="text" id="birth">
                </div>
            </div>
            <div class="form-group">
                <label for="address" class="col-sm-2 control-label">地址：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" name="address" id="address"placeholder="可设置为办公地址" value="${sessionScope.admin.address}" >
                </div>
            </div>
            </fieldset>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10 pull-right">
                    <button id="modifyinfo" type="button" onclick="modifypersonalinfo()" class="btn btn-primary">修改资料</button>
                    <div id="savediv">
                        <button id="saveinfo" type="button" onclick="saveypersonalinfo()" class="btn btn-info">保存资料</button>
                        <button id="cancelmodifyinfo" type="button" onclick="cancelmodify()" class="btn btn-default">取消修改</button>
                    </div>
                </div>
            </div>
        </form>
        <div>
            <p><strong>附加设置</strong></p>
        </div>
        <div class="col-sm-2" style="padding-top: 10px;text-align:right">
            <%--<button type="button" class="btn btn-link">绑定手机</button><br>--%>
            <button type="button" class="btn btn-link" data-toggle="modal" data-target="#changepassword">修改密码</button>
        </div>
    </div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="changepassword" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">
                    修改密码
                </h4>
            </div>
            <div class="modal-body">
               <div>
                   <form class="form-horizontal" role="form" id="changepwdform">
                   <div class="form-group">
                       <label for="oldpassword" class="col-sm-3 control-label">原密码：</label>
                       <div class="col-sm-7">
                           <input type="password" class="form-control" name="oldpassword" id="oldpassword"placeholder="输入原密码">
                       </div>
                   </div>
                   <div class="form-group">
                       <label for="newpassword1" class="col-sm-3 control-label">新密码：</label>
                       <div class="col-sm-7">
                           <input type="password" class="form-control" name="newpassword1" id="newpassword1"placeholder="设置新密码">
                       </div>
                   </div>
                   <div class="form-group">
                       <label for="newpassword2" class="col-sm-3 control-label">重复新密码：</label>
                       <div class="col-sm-7">
                           <input type="password" class="form-control" name="newpassword2" id="newpassword2"placeholder="确认新密码">
                       </div>
                   </div>
                   </form>
               </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="subPassword()">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    function subPassword(){
        var oldpassword=$("#oldpassword").val();
        var newpassword1=$("#newpassword1").val();
        var newpassword2=$("#newpassword2").val();
        if(newpassword1!=newpassword2){
            alert("新密码两次输入不同，请重新修改密码！");
        }else{
            $.post("${hkxyPath}/user/personal-change-password",{"id":adminid,"oldpassword":oldpassword,"newpassword":newpassword1},function (result) {
                if(result.code==0){
                    tips(0);
                    console.log(result.message);
                }else if(result.code==2){
                    alert(result.message);
                }else{
                    tips(1);
                }

            })
        }
        $('#changepwdform input').val("");
    }
</script>
</body>
</html>
